package com.cirnoworks.common;

import java.nio.ByteBuffer;

public final class ByteBufferUtil {

	public static String getString(ByteBuffer buf) {
		char len = buf.getChar();
		StringBuilder sb = new StringBuilder(len);
		for (int i = 0; i < len; i++) {
			sb.append(buf.getChar());
		}
		return sb.toString();
	}

	public static void putString(ByteBuffer buf, String str) {
		buf.putChar((char) str.length());
		for (int i = 0, max = (char) str.length(); i < max; i++) {
			buf.putChar(str.charAt(i));
		}
	}
}
